package com.baiqian.doupo.world;

import com.baiqian.doupo.Utils;
import com.baiqian.doupo.block.BlockRegistry;
import com.google.common.collect.ImmutableSet;
import net.minecraft.block.Blocks;
import net.minecraft.block.CropsBlock;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.gen.blockplacer.SimpleBlockPlacer;
import net.minecraft.world.gen.blockstateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.feature.*;

public class ModFeatures {
    public static final class Configs {
        /*
        .tries(64)//生成数量
        .whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK))
        .preventProjection()//需不需要根据noise生成
        .xSpread()
        .ySpread()
        .zSpread()//xyz扩散范围
        .replaceable()//会不会替换方块
        .requiresWater()//旁边需不需要有水
        .blacklist()
        .build();
        * */

        public static final BlockClusterFeatureConfig Zi_Ye_Lan_Cao_CONFIG = (
                new BlockClusterFeatureConfig.Builder(
                        new SimpleBlockStateProvider(
                                BlockRegistry.zi_ye_lan_cao.get().getDefaultState().with(CropsBlock.AGE, Integer.valueOf(7))
                        ),
                        SimpleBlockPlacer.PLACER))
                .tries(10)//生成数量
                .whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK))
                .preventProjection()//需不需要根据noise生成
                .xSpread(7)
                .ySpread(7)
                .zSpread(7)//xyz扩散范围
//                        .replaceable()//会不会替换方块
//                        .requiresWater()//旁边需不需要有水
//                        .blacklist()
                .build();

        public static final BlockClusterFeatureConfig Xi_Gu_Hua_CONFIG = (
                new BlockClusterFeatureConfig.Builder(
                        new SimpleBlockStateProvider(
                                BlockRegistry.xi_gu_hua.get().getDefaultState().with(CropsBlock.AGE, Integer.valueOf(7))
                        ),
                        SimpleBlockPlacer.PLACER))
                        .tries(10)//生成数量
                        .whitelist(ImmutableSet.of(Blocks.GRASS_BLOCK))
                        .preventProjection()//需不需要根据noise生成
                        .xSpread(7)
                        .ySpread(7)
                        .zSpread(7)//xyz扩散范围
//                        .replaceable()//会不会替换方块
//                        .requiresWater()//旁边需不需要有水
//                        .blacklist()
                        .build();


    }
    public static final ConfiguredFeature<?, ?> Zi_Ye_Lan_Cao= register("zi_ye_lan_cao",
            Feature.RANDOM_PATCH.withConfiguration(Configs.Zi_Ye_Lan_Cao_CONFIG)
                    .withPlacement(Features.Placements.PATCH_PLACEMENT)
                    .withPlacement(Features.Placements.VEGETATION_PLACEMENT)
                    .withPlacement(Features.Placements.HEIGHTMAP_PLACEMENT)
                    .count(4)
//                    .range(3)
    );

    public static final ConfiguredFeature<?, ?> Xi_Gu_Hua= register("xi_gu_hua",
            Feature.RANDOM_PATCH.withConfiguration(Configs.Xi_Gu_Hua_CONFIG)
                    .withPlacement(Features.Placements.PATCH_PLACEMENT)
                    .withPlacement(Features.Placements.VEGETATION_PLACEMENT)
                    .withPlacement(Features.Placements.HEIGHTMAP_PLACEMENT)
                    .count(4)
//                    .range(3)
    );



    private static <FC extends IFeatureConfig> ConfiguredFeature<FC, ?> register(String key, ConfiguredFeature<FC, ?> configuredFeature) {
        return Registry.register(WorldGenRegistries.CONFIGURED_FEATURE, new ResourceLocation(Utils.MOD_ID, key), configuredFeature);
    }
}
